<?php
namespace Mob\Model;

use Think\Model;

/**字段数据模型，通过该模型可以方便地对字段信息实现读和取
 * Class DataModel
 */
class DeptModel extends Model
{

  public function addDept($deptId,$deptName,$deptType,$superId=0,$schooId='10183')
  {

  	$data['deptId']=$deptId;
  	$data['deptName']=$deptName;
  	$data['deptType']=$deptType;
  	$data['superId']=$superId;
  	$data['schooId']=$schooId;
   return   $this->add($data);

  }
 public function get_AllDeptList($schooId='10183')
 {
    $where = array('schooId'=>$schooId,'status'=>1,'deptType'=>1);
    $dept = $this->where($where)->field('schooId, status, deptId, deptName')->select();

    foreach($dept as &$v)
    {
    $v['lowerDept'] = $this->get_lowerDeptList($v['deptId'],2,$schooId);
    }
    unset($v);
    return $dept;

 }
 public function get_lowerDeptList($deptId,$deptType=2,$schooId='10183')
 {
 return $this->where(array('schooId'=>$schooId,'status'=>1,'superId'=>$deptId))->field('schooId, status, deptId, deptName')->select();

 }
 public function get_deptFullName($deptId,$schooId=10183)
 {
 $dept = new \ Think \ Model();
 return $dept->query("select t2.deptName as collegeName,t2.deptId as collegeId,t1.deptName as  branchName ,t1.deptId as branchId from  ocenter_dept t1,ocenter_dept t2 where t1.deptId =$deptId and t1.schooId = $schooId and t1.status =1  and t1.superId = t2.deptId and t2.schooId =
  $schooId and t2.status =1 limit 1")[0];
 }

 public function is_authority($manageId,$deptId,$schooId=10183)
 {
 $dept_info = $this->get_deptInfo($deptId,2,$schooId);
 if($dept_info['manageUid']==$manageId)
 {
 return true;
 }
 }
 public function get_deptInfo($deptId,$deptType=2,$schooId=10183)
 {
 return $this->where(array('deptId'=>$deptId,'schooId'=>$schooId,'status'=>1,'deptType'=>$deptType))->field('deptId,deptName,schooId,deptType,superId,manageUid')->find();
 }
 //更新部门管理人
 public function update_deptManageUid($deptId,$manageUid,$schooId=10183)
 {
  $this->where(array('deptId'=>$deptId,'schooId'=>$schooId,'status'=>1))->save(array('manageUid'=>$manageUid));
  return true;
 }







}